package com.lilingguo.anime.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 文件路径
 *
 * @Author: GuoZi
 * @Date: 2020/11/03 16:33
 */
@Data
@ApiModel("文件路径")
@TableName("tab_folder")
public class FolderPo implements Comparable<FolderPo> {

    @TableId(type = IdType.AUTO)
    @ApiModelProperty("主键id")
    private Integer id;

    @ApiModelProperty("漫画页数")
    private Integer size;

    @ApiModelProperty("是否为根目录")
    private Boolean root;

    @ApiModelProperty("添加时间")
    private Long createTime;

    @ApiModelProperty("文件夹名")
    private String name;

    @Override
    public int compareTo(FolderPo otherFolder) {
        Integer otherSize = otherFolder.getSize();
        boolean b1 = this.size > 0;
        boolean b2 = otherSize > 0;
        if (b1 ^ b2) {
            // sorted by size
            return this.size - otherSize;
        }
        // sorted by name
        String otherName = otherFolder.getName();
        int result = this.name.length() - otherName.length();
        if (result == 0) {
            // sorted by length of name
            return this.name.compareTo(otherName);
        }
        return result;
    }

}
